﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {

    /// <summary>
    /// 速度
    /// </summary>
    public int Speed = 10;
    private Rigidbody playerRgd;

    // Use this for initialization
    void Start () {
        playerRgd = GetComponent<Rigidbody>();
        GetComponent<MovingModel>().ShowTitle(gameObject.name);
    }
	
	// Update is called once per frame
	void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        if (h != 0 || v != 0) {
            Vector3 vector = new Vector3(h, 0, v);
            playerRgd.MovePosition(playerRgd.position + vector * Speed * Time.deltaTime);
            Quaternion targetRotation = Quaternion.LookRotation(vector);
            Quaternion newRotation = Quaternion.Lerp(playerRgd.rotation, targetRotation, Speed * Time.deltaTime);
            playerRgd.MoveRotation(newRotation);
        }
	}

    private void UpdateTransform() {

    }
}
